﻿package igz.fleaxy.net {
	import igz.fleaxy.events.CommEvent;
	import igz.fleaxy.pattern.AbstractFactory;
	
	/**
	 * @author Intelygenz | www.intelygenz.com
	 * 
	 * Manager de mensajes DTO sobre el COM
	 */
	public class CommMessageManager extends AbstractFactory {

		protected var _JsonBlockName:String = "message";

		protected var _MessageDto : CommMessageDto;
		public function get $MessageDto() : CommMessageDto {
			return _MessageDto;
		}

		public function CommMessageManager() {
			super( CommMessageDto );
		}

		public function $LoadMessage ( p_commEvent:CommEvent ) : void {
			_MessageDto = null;
			switch ( p_commEvent.$CommResponseType ) {
				case CommResponseType.$JSON :
					var rootTag : String = "";
						for ( rootTag in p_commEvent.$ResponseJSON ) { break; }
						if ( p_commEvent.$ResponseJSON[rootTag] != null && p_commEvent.$ResponseJSON[rootTag].hasOwnProperty( _JsonBlockName ) ) {
							$LoadFromJSON( p_commEvent.$ResponseJSON, _JsonBlockName );
						}
					break;
			}
			if ( _Dtos.length > 0 ) {
				_MessageDto = _Dtos[0] as CommMessageDto;
			}
		}

	}

}